/*     */ package com.Ticker.util;
/*     */ 
/*     */ import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.AbstractListModel;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
/*     */ 
/*     */ public class OptionsDialog extends JDialog
/*     */   implements ActionListener
/*     */ {
/*     */   private static final long serialVersionUID = 4917258637695033016L;
/*  29 */   private JTextField symbolField = new JTextField(10);
/*     */   private JList currentSymbols;
/*     */   private OptionsListener listener;
/*     */ 
/*     */   public OptionsDialog(JFrame owner, OptionsListener listener, String[] symbols)
/*     */   {
/*  40 */     super(owner, "Options", true);
/*  41 */     this.listener = listener;
/*  42 */     DialogListModel model = new DialogListModel(symbols);
/*     */ 
/*  44 */     this.currentSymbols = new JList(model);
/*  45 */     this.currentSymbols.setSelectionMode(0);
/*     */ 
/*  47 */     createGUI();
/*     */   }
/*     */ 
/*     */   public static void centerFrame(Window frame)
/*     */   {
/*  54 */     Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
/*  55 */     Dimension frameSize = frame.getSize();
/*  56 */     frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
/*     */   }
/*     */ 
/*     */   private void createGUI() {
/*  60 */     this.symbolField.addActionListener(this);
/*  61 */     this.symbolField.setActionCommand("add");
/*     */ 
/*  63 */     JButton addSymbolButton = new JButton("Add");
/*  64 */     addSymbolButton.setActionCommand("add");
/*  65 */     addSymbolButton.addActionListener(this);
/*     */ 
/*  67 */     JButton removeSymbolButton = new JButton("Remove");
/*  68 */     removeSymbolButton.setActionCommand("remove");
/*  69 */     removeSymbolButton.addActionListener(this);
/*     */ 
/*  71 */     JButton closeButton = new JButton("Close");
/*  72 */     closeButton.setActionCommand("close");
/*  73 */     closeButton.addActionListener(this);
/*     */ 
/*  75 */     getContentPane().setLayout(new GridBagLayout());
/*  76 */     GridBagConstraints gbc = new GridBagConstraints();
/*  77 */     gbc.gridx = 0;
/*  78 */     gbc.gridy = 0;
/*  79 */     gbc.fill = 2;
/*  80 */     gbc.insets = new Insets(5, 5, 0, 5);
/*  81 */     getContentPane().add(this.symbolField, gbc);
/*     */ 
/*  83 */     gbc.gridx += 1;
/*  84 */     gbc.anchor = 17;
/*  85 */     getContentPane().add(addSymbolButton, gbc);
/*     */ 
/*  87 */     gbc.gridx = 1;
/*  88 */     gbc.gridy = 1;
/*  89 */     gbc.anchor = 11;
/*  90 */     getContentPane().add(removeSymbolButton, gbc);
/*     */ 
/*  92 */     gbc.gridx = 0;
/*  93 */     gbc.weightx = 1.0D;
/*  94 */     gbc.weighty = 1.0D;
/*  95 */     gbc.gridheight = 2;
/*  96 */     gbc.fill = 1;
/*  97 */     gbc.insets = new Insets(5, 5, 5, 5);
/*  98 */     JScrollPane scrollPane = new JScrollPane(this.currentSymbols, 20, 30);
/*  99 */     getContentPane().add(scrollPane, gbc);
/*     */ 
/* 101 */     gbc.gridx = 1;
/* 102 */     gbc.gridy = 2;
/* 103 */     gbc.gridheight = 1;
/* 104 */     gbc.fill = 0;
/* 105 */     gbc.anchor = 14;
/* 106 */     getContentPane().add(closeButton, gbc);
/*     */ 
/* 108 */     pack();
/* 109 */     centerFrame(this);
/* 110 */     setResizable(false);
/* 111 */     setVisible(true);
/*     */   }
/*     */ 
/*     */   private void addSymbol() {
/* 115 */     String symbol = this.symbolField.getText().toUpperCase().trim();
/* 116 */     this.symbolField.setText("");
/* 117 */     if ((symbol != null) && (!symbol.equals(""))) {
/* 118 */       DialogListModel model = (DialogListModel)this.currentSymbols.getModel();
/* 119 */       for (int i = 0; i < model.getSize(); ++i) {
/* 120 */         String s = (String)model.getElementAt(i);
/* 121 */         if (s.equals(symbol)) {
/* 122 */           return;
/*     */         }
/*     */       }
/* 125 */       model.add(symbol);
/* 126 */       this.listener.addSymbol(symbol);
/*     */     }
/*     */   }
/*     */ 
/*     */   public void actionPerformed(ActionEvent e) {
/* 131 */     String command = e.getActionCommand();
/* 132 */     if (command.equals("add")) {
/* 133 */       addSymbol();
/* 134 */     } else if (command.equals("remove")) {
/* 135 */       DialogListModel model = (DialogListModel)this.currentSymbols.getModel();
/* 136 */       if (model.getSize() < 0) {
/* 137 */         return;
/*     */       }
/*     */ 
/* 140 */       Object obj = this.currentSymbols.getSelectedValue();
/* 141 */       if ((obj == null) || 
/* 142 */         (!model.remove(obj))) return;
/* 143 */       this.listener.removeSymbol(obj.toString().toUpperCase());
/*     */     }
/* 146 */     else if (command.equals("close")) {
/* 147 */       dispose();
/*     */     }
/*     */   }
/*     */ 
/*     */   private class DialogListModel extends AbstractListModel
/*     */   {
/*     */     private static final long serialVersionUID = -2222457582345410750L;
/* 156 */     private List<String> data = new ArrayList<String>();
/*     */ 
/*     */     public DialogListModel(String[] symbols) {
/* 159 */       for (int i = 0; i < symbols.length; ++i)
/* 160 */         this.data.add(symbols[i].toUpperCase());
/*     */     }
/*     */ 
/*     */     public int getSize()
/*     */     {
/* 165 */       return this.data.size();
/*     */     }
/*     */ 
/*     */     public boolean remove(Object val) {
/* 169 */       if (val == null) {
/* 170 */         return false;
/*     */       }
/* 172 */       boolean ret = this.data.remove(val.toString().toUpperCase());
/* 173 */       if (ret) {
/* 174 */         fireContentsChanged(this, 0, this.data.size() - 1);
/*     */       }
/*     */ 
/* 177 */       return ret;
/*     */     }
/*     */ 
/*     */     public Object getElementAt(int index) {
/* 181 */       if ((index >= getSize()) || (index < 0)) {
/* 182 */         return null;
/*     */       }
/* 184 */       return this.data.get(index);
/*     */     }
/*     */ 
/*     */     public void add(Object val) {
/* 188 */       if (val == null) {
/* 189 */         return;
/*     */       }
/* 191 */       this.data.add(val.toString().toUpperCase());
/* 192 */       fireContentsChanged(this, this.data.size() - 2, this.data.size() - 1);
/*     */     }
/*     */   }
/*     */ }

/* Location:           C:\Users\os\Downloads\TrimOnline.jar
 * Qualified Name:     Ticker.util.OptionsDialog
 * JD-Core Version:    0.5.4
 */